package java3.io;

public class Posiciones {

    public static final int pawn = 1;
    public static final int knight = 2;
    public static final int bishop = 3;
    public static final int rook = 4;
    public static final int queen = 5;
    public static final int king = 6;
    public static final int PAWN = 11;
    public static final int KNIGHT = 12;
    public static final int BISHOP = 13;
    public static final int ROOK = 14;
    public static final int QUEEN = 15;
    public static final int KING = 16;
    public static final int white = 0;
    public static final int black = 1;
    public static final int vacio = 0;
    public static final int sincolor = 2;

    public int[][] vacio() {
        return new int[][]{{vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio},
                    {sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor}};
    }

    public int[][] inicio() {

        return this.voltearFilas(
                this.completarColores(
                new int[]{rook, knight, bishop, queen, king, bishop, knight, rook,
                    pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
                    vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                    vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                    vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                    vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
                    PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN,
                    ROOK, KNIGHT, BISHOP, QUEEN, KING, BISHOP, KNIGHT, ROOK}));

//        Object o2 = new int[]{
//                        ROOK, KNIGHT, BISHOP, KING, QUEEN, BISHOP, KNIGHT, ROOK,
//                        PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN,
//                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
//                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
//                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,
//                        vacio, vacio, vacio, vacio, vacio, vacio, vacio, vacio,                        
//                        pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
//                        rook, knight, bishop, king, queen, bishop, knight, rook,
//                        };
    }

    public int[][] valid4() {
        return new int[][]{{
                        rook, knight, bishop, vacio, king, bishop, knight, rook,
                        pawn, pawn, vacio, vacio, vacio, vacio, vacio, pawn,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, pawn, vacio,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, pawn, vacio, vacio, vacio, vacio, vacio, vacio,
                        pawn, vacio, vacio, queen, vacio, pawn, vacio, pawn,
                        rook, knight, bishop, queen, king, bishop, knight, rook},
                    {white, white, white, sincolor, white, white, white, white,
                        white, white, sincolor, sincolor, sincolor, sincolor, sincolor, white,
                        sincolor, sincolor, sincolor, sincolor, white, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, white, sincolor,
                        sincolor, sincolor, sincolor, sincolor, black, sincolor, sincolor, sincolor,
                        sincolor, black, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        black, sincolor, sincolor, white, sincolor, black, sincolor, black,
                        black, black, black, black, black, black, black, black
                    }};
    }

    public int[][] valid5() {
        return new int[][]{{
                        rook, knight, bishop, vacio, king, bishop, knight, rook,
                        pawn, pawn, vacio, vacio, vacio, vacio, vacio, pawn,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, pawn, vacio,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, pawn, vacio, vacio, vacio, vacio, vacio, vacio,
                        pawn, vacio, vacio, knight, vacio, pawn, vacio, pawn,
                        rook, vacio, bishop, queen, king, bishop, knight, rook},
                    {white, white, white, sincolor, white, white, white, white,
                        white, white, sincolor, sincolor, sincolor, sincolor, sincolor, white,
                        sincolor, sincolor, sincolor, sincolor, white, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, white, sincolor,
                        sincolor, sincolor, sincolor, sincolor, black, sincolor, sincolor, sincolor,
                        sincolor, black, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        black, sincolor, sincolor, black, sincolor, black, sincolor, black,
                        black, sincolor, black, black, black, black, black, black
                    }};
    }

    public int[][] valid6() {
        return new int[][]{{
                        rook, knight, bishop, vacio, king, bishop, knight, rook,
                        pawn, pawn, vacio, vacio, vacio, vacio, vacio, pawn,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, pawn, vacio,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, pawn, vacio, vacio, vacio, vacio, vacio, vacio,
                        pawn, vacio, vacio, bishop, vacio, pawn, vacio, pawn,
                        rook, knight, vacio, queen, king, bishop, knight, rook},
                    {white, white, white, sincolor, white, white, white, white,
                        white, white, sincolor, sincolor, sincolor, sincolor, sincolor, white,
                        sincolor, sincolor, sincolor, sincolor, white, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, white, sincolor,
                        sincolor, sincolor, sincolor, sincolor, black, sincolor, sincolor, sincolor,
                        sincolor, black, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        black, sincolor, sincolor, black, sincolor, black, sincolor, black,
                        black, black, sincolor, black, black, black, black, black
                    }};
    }
    
    public int[][] valid7() {
        return new int[][]{{
                        rook, vacio, bishop, king, vacio, bishop, knight, rook,
                        pawn, pawn, vacio, knight, vacio, vacio, vacio, pawn,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, pawn, vacio,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, pawn, vacio, vacio, vacio, vacio, vacio, vacio,
                        pawn, vacio, vacio, queen, vacio, pawn, vacio, pawn,
                        rook, knight, bishop, vacio, king, bishop, knight, rook},
                    {white, sincolor, white, white, sincolor, white, white, white,
                        white, white, sincolor, white, sincolor, sincolor, sincolor, white,
                        sincolor, sincolor, sincolor, sincolor, white, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, white, sincolor,
                        sincolor, sincolor, sincolor, sincolor, black, sincolor, sincolor, sincolor,
                        sincolor, black, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        black, sincolor, sincolor, black, sincolor, black, sincolor, black,
                        black, black, black, sincolor, black, black, black, black
                    }};
    }
    
    public int[][] valid8() {
        return new int[][]{{
                        rook, knight, bishop, vacio, king, bishop, knight, rook,
                        pawn, pawn, vacio, vacio, vacio, vacio, vacio, pawn,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, vacio, vacio, vacio, vacio, vacio, pawn, vacio,
                        vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                        vacio, pawn, vacio, vacio, vacio, vacio, vacio, vacio,
                        pawn, vacio, vacio, king, vacio, pawn, vacio, pawn,
                        rook, knight, bishop, queen, vacio, bishop, knight, rook},
                    {white, white, white, sincolor, white, white, white, white,
                        white, white, sincolor, sincolor, sincolor, sincolor, sincolor, white,
                        sincolor, sincolor, sincolor, sincolor, white, sincolor, sincolor, sincolor,
                        sincolor, sincolor, sincolor, sincolor, sincolor, sincolor, white, sincolor,
                        sincolor, sincolor, sincolor, sincolor, black, sincolor, sincolor, sincolor,
                        sincolor, black, sincolor, sincolor, sincolor, sincolor, sincolor, sincolor,
                        black, sincolor, sincolor, black, sincolor, black, sincolor, black,
                        black, black, black, black, sincolor, black, black, black
                    }};
    }
    
    private int[][] voltearColumnas(int[][] t) {
        int[][] x = new int[2][64];

        for (int i = 0; i < 64; i++) {
            x[0][i] = t[0][(8 * (i / 8 + 1) - 1) - i % 8];
            x[1][i] = t[1][(8 * (i / 8 + 1) - 1) - i % 8];
        }

        return x;
    }

    private int[][] voltearFilas(int[][] t) {
        int[][] x = new int[2][64];

        for (int i = 0; i < 64; i++) {
            x[0][i] = t[0][(56 - (i / 8) * 8) + i % 8];
            x[1][i] = t[1][(56 - (i / 8) * 8) + i % 8];
        }

        return x;
    }

    public int[][] temp() {
        return this.voltearFilas(this.completarColores(new int[]{
                    rook, knight, bishop, vacio, king, bishop, knight, rook,
                    pawn, vacio, vacio, vacio, vacio, pawn, vacio, pawn,
                    vacio, pawn, vacio, vacio, vacio, vacio, vacio, vacio,
                    vacio, vacio, vacio, vacio, pawn, vacio, vacio, vacio,
                    vacio, PAWN, vacio, vacio, vacio, vacio, queen, vacio,
                    vacio, vacio, KNIGHT, vacio, PAWN, vacio, vacio, vacio,
                    PAWN, vacio, vacio, vacio, vacio, vacio, vacio, PAWN,
                    ROOK, vacio, BISHOP, vacio, KING, BISHOP, KNIGHT, ROOK}));
    }
    
    private int[][] completarColores(int[] i) {
        int[][] t = new int[2][64];

        for (int j = 0; j < i.length; j++) {
            int k = i[j];

            switch (k) {
                case vacio:
                    t[0][j] = vacio;
                    t[1][j] = sincolor;
                    break;
                case pawn:
                case PAWN:
                    t[0][j] = pawn;
                    t[1][j] = (k == pawn ? black : white);
                    break;
                case knight:
                case KNIGHT:
                    t[0][j] = knight;
                    t[1][j] = (k == knight ? black : white);
                    break;
                case bishop:
                case BISHOP:
                    t[0][j] = bishop;
                    t[1][j] = (k == bishop ? black : white);
                    break;
                case rook:
                case ROOK:
                    t[0][j] = rook;
                    t[1][j] = (k == rook ? black : white);
                    break;
                case queen:
                case QUEEN:
                    t[0][j] = queen;
                    t[1][j] = (k == queen ? black : white);
                    break;
                case king:
                case KING:
                    t[0][j] = king;
                    t[1][j] = (k == king ? black : white);
                    break;
            }
        }

        return t;
    }
}
